
#pragma once

#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>

#include <iostream>

using namespace cv;

namespace course_05_perspective
{

    //
    void warp(std::string path)
    {

        Mat matrix, imgWarp;

        Mat image = imread(path);

        float w = 250, h = 350;
        Point2f src[4] = {{1098, 386}, {1374, 521}, {845, 652}, {1129, 810}};
        Point2f dst[4] = {{0.0f, 0.0f}, {w, 0.0f}, {0.0f, h}, {w, h}};

        //将一个非矩形的四边形做仿射变换变为正视的矩形
        matrix = getPerspectiveTransform(src, dst);
        warpPerspective(image, imgWarp, matrix, Point(w, h));

        //对检测的四个点画上圆点
        for (int i = 0; i < 4; i++)
        {
            circle(image, src[i], 10, Scalar(150.0, 0.0, 150), FILLED);
        }

        imshow("IMAGE", image);
        imshow("IMAGE-perspective", imgWarp);

        waitKey(0);
    }

}